package com.by.controller;

import com.by.bean.Employee;
import com.by.common.bean.Page;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.service.EmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @author HY
 * @version 1.0
 * @description
 * @date 2025/2/18
 * @since JDK21
 */
@Api(tags = "员工管理")
@RequestMapping("/api/employee")
@RestController
public class EmployeeController extends BaseController {
    @Autowired
    EmployeeService employeeService;

    @ApiOperation(value = "根据员工名字和部门名字查询")
    @GetMapping("/query/{name}/{departmentName}")
    public ResultBean query(@PathVariable("name") String name,@PathVariable(value = "departmentName") String departmentName){
        List<Employee> employees = employeeService.queryByName(name,departmentName);

        return employees!=null?success("员工查询成功",employees):fail("员工查询失败");
    }
    @ApiOperation(value = "员工查询")
    @GetMapping("/query/list")
    public ResultBean query(Page page){
        PageBean employees = employeeService.queryList(page.getPage(), page.getPageSize());
        return employees!=null?success("员工查询成功",employees):fail("员工查询失败");

    }

    @ApiOperation(value = "添加员工")
    @PostMapping("/save")
    public ResultBean save(@RequestBody Employee employee){
        int save = employeeService.save(employee);

        return save!=0?success("员工添加成功"):fail("员工添加失败");
    }

    @ApiOperation(value = "修改员工")
    @PutMapping("/update")
    public ResultBean update(@RequestBody Employee employee){
        int update = employeeService.update(employee);
        return update!=0?success("员工修改成功"):fail("员工修改失败");
    }

    @ApiOperation(value = "删除员工")
    @DeleteMapping("/delete/{id}")
    public ResultBean delete(@PathVariable("id") String id){
        int delete = employeeService.delete(id);
        return delete!=0?success("员工删除成功"):fail("员工删除失败");
    }

}
